//
//  SelectedNumberViewController.m
//  CaiPiao
//
//  Created by apple on 2018/5/19.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "SelectedNumberViewController.h"
#import "SelectedNumberView.h"

static CGFloat spacingWith = 10;
static CGFloat ballWidth = 40;

@interface SelectedNumberViewController ()

@property(nonatomic,retain)UIView* numberBoxView;

@property (weak, nonatomic) IBOutlet UIView *selectStyleBoxView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *styleBoxTopCons;


//普通选号红球区
@property(nonatomic,retain)NSArray* redBallArray;
@property(nonatomic,retain)UIView* redBallBoxView;
@property(nonatomic,retain)NSMutableArray* seletedRedNumArray;

//胆拖红球区
@property(nonatomic,retain)NSArray* TugRedBallArray;
@property(nonatomic,retain)UIView* TugRedBallBoxView;
@property(nonatomic,retain)NSMutableArray* seletedTugRedNumArray;

//普通选号蓝球区
@property(nonatomic,retain)NSArray* blueBallArray;
@property(nonatomic,retain)UIView* blueBallBoxView;
@property(nonatomic,retain)NSMutableArray* seletedBlueNumArray;

//胆拖蓝球区
@property(nonatomic,retain)NSArray* TugblueBallArray;
@property(nonatomic,retain)UIView* TugblueBallBoxView;
@property(nonatomic,retain)NSMutableArray* seletedTugBlueNumArray;

@property (weak, nonatomic) IBOutlet UITableView *numberTableView;
@property (weak, nonatomic) IBOutlet UILabel *CalculateMoneyLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameAndEndTime;
@property(nonatomic,retain)NSDictionary* nameDic;


@property (nonatomic,retain)UIButton* randomButton;

@end

@implementation SelectedNumberViewController{
    NSMutableArray* randomRednumberViewArray;
    NSMutableArray* randomBluenumberViewArray;
    NSMutableArray* tugRedNumberViewArray;
    NSMutableArray* tugBlueNumberViewArray;
    NSString* currentID;
    NSInteger styleIndex;
    BOOL openStyleView;
    
    UIButton* titleButton;
}

-(void)updateViewConstraints{
    [super updateViewConstraints];
    self.styleBoxTopCons.constant = openStyleView?0:-100;
}

- (IBAction)selectStyleAction:(UIButton *)sender {
    for (UIView* view in self.selectStyleBoxView.subviews) {
        if (view.tag>100) {
            UIButton* styleButton = (UIButton*)view;
            [styleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
    }
    
    [sender setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    
    NSString* xuanhaoString = @"普通选号";
    switch (sender.tag) {
        case 101:
            styleIndex = 0;
            xuanhaoString = @"普通选号";
            break;
        case 102:
            styleIndex = 1;
            xuanhaoString = @"胆拖选号";
            break;
        default:
            break;
    }
   
    NSString* titleString = [NSString stringWithFormat:@"%@%@",[SelectionNumManager shared].currentLotteryName,xuanhaoString];
    [titleButton setTitle:titleString forState:UIControlStateNormal];
    [self removeAllHighLightState];
    [self.seletedRedNumArray removeAllObjects];
    [self.seletedBlueNumArray removeAllObjects];
    [self showStyleView];
    [self.numberTableView reloadData];
}
#pragma mark - 检查选号个数是否正确
-(NSString*)checkNumberCountWith:(NSInteger)typeIndex{
    NSString* callBackString = @"";
    
    NSInteger redMaxCount = 0;
    NSInteger redMinCount = 0;
    NSInteger TugRedMaxCount = 0;
    NSInteger TugRedMinCount = 0;
    
    NSInteger blueMaxCount = 0;
    NSInteger blueMinCount = 0;
    NSInteger TugBlueMaxCount = 0;
    NSInteger TugBlueMinCount = 0;
    
    NSInteger currentIDForLot = [currentID integerValue];
    switch (styleIndex) {
        case 0:{
            redMaxCount = (currentIDForLot==3)?20:18;//最多选
            redMinCount = (currentIDForLot==3)?6:5;//
            blueMaxCount = [randomBluenumberViewArray count];
            blueMinCount = (currentIDForLot==3)?1:2;
            
        }
            break;
        case 1:{
            redMaxCount = (currentIDForLot==3)?5:4;
            redMinCount = (currentIDForLot==3)?1:1;
            blueMaxCount = (currentIDForLot==3)?[randomBluenumberViewArray count]:1;
            blueMinCount = (currentIDForLot==3)?1:0;
            
            TugRedMaxCount = [tugRedNumberViewArray count];
            TugRedMinCount = 2;
            TugBlueMaxCount = [tugBlueNumberViewArray count];
            TugBlueMinCount = (currentIDForLot==3)?0:2;
        }
            break;
        default:
            break;
    }
    
    
//    红球
    if ([self.seletedRedNumArray count]>redMaxCount) {
        callBackString = (styleIndex==0)?[NSString stringWithFormat:@"最多只能选择%ld个红球",redMaxCount]:[NSString stringWithFormat:@"最多只能选择%ld个红色胆球",redMaxCount];
        
        if (typeIndex==1||typeIndex==0) {
            return callBackString;
        }
    }
    if ([self.seletedRedNumArray count]<redMinCount) {
        callBackString = (styleIndex==0)?[NSString stringWithFormat:@"至少选择%ld个红球",redMinCount]:[NSString stringWithFormat:@"请选择%ld-%ld个红色胆球",redMinCount,redMaxCount];
        
        if (typeIndex==1||typeIndex==0) {
            return callBackString;
        }
    }
    
    
    if ([self.seletedTugRedNumArray count]==TugRedMaxCount) {
        callBackString = @"";
        
    }
    if ([self.seletedTugRedNumArray count]<TugRedMinCount) {
        callBackString = (styleIndex==0)?@"":[NSString stringWithFormat:@"至少选择%ld个红色拖球",TugRedMinCount];
        
        if ((typeIndex==3||typeIndex==0)&&([callBackString length]>0)) {
            return callBackString;
        }
    }
//    蓝球
    if ([self.seletedBlueNumArray count]>blueMaxCount) {
        callBackString = (styleIndex==0)?@"":[NSString stringWithFormat:@"最多只能选择%ld个蓝色胆球",blueMaxCount];
        if ((typeIndex==2||typeIndex==0)&&([callBackString length]>0)) {
            return callBackString;
        }
    }
    if ([self.seletedBlueNumArray count]<blueMinCount) {
        callBackString = (styleIndex==0)?[NSString stringWithFormat:@"至少选择%ld个蓝球",blueMinCount]:@"";
        if ((typeIndex==2||typeIndex==0)&&([callBackString length]>0)) {
            return callBackString;
        }
    }
    
    
    if ([self.seletedTugBlueNumArray count]==TugBlueMaxCount) {
        callBackString = @"";
    }
    if ([self.seletedTugBlueNumArray count]<TugBlueMinCount) {
        callBackString = (styleIndex==0)?@"":[NSString stringWithFormat:@"至少选择%ld个蓝色拖球",TugRedMinCount];
        if ((typeIndex==4||typeIndex==0)&&([callBackString length]>0)) {
            return callBackString;
        }
    }
    
    return callBackString;
}

#pragma mark - 计算注数和购买需要的金钱
-(void)CalculateMoneyAction{

    NSInteger redCount = 0;
    NSInteger blueCount = 0;
    
    switch ([currentID integerValue]) {
        case 3:{
            redCount = [self.seletedRedNumArray count]+[self.seletedTugRedNumArray count];
            blueCount = [self.seletedBlueNumArray count];
            if (redCount<6||blueCount==0) {
                NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:@"0注 0元"];
                [AttributedStr addAttribute:NSForegroundColorAttributeName
                                      value:[UIColor redColor]
                                      range:NSMakeRange(0, 1)];
                [AttributedStr addAttribute:NSForegroundColorAttributeName
                                      value:[UIColor redColor]
                                      range:NSMakeRange(3, 1)];
                self.CalculateMoneyLabel.attributedText = AttributedStr;
                return;
            }
        }
            break;
        case 4:{
            redCount = [self.seletedRedNumArray count]+[self.seletedTugRedNumArray count];
            blueCount = [self.seletedBlueNumArray count]+[self.seletedTugBlueNumArray count];;
            if (redCount<5||blueCount<2) {
                NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:@"0注 0元"];
                [AttributedStr addAttribute:NSForegroundColorAttributeName
                                      value:[UIColor redColor]
                                      range:NSMakeRange(0, 1)];
                [AttributedStr addAttribute:NSForegroundColorAttributeName
                                      value:[UIColor redColor]
                                      range:NSMakeRange(3, 1)];
                self.CalculateMoneyLabel.attributedText = AttributedStr;
                return;
            }
        }
            break;
            
        default:
            break;
    }
    

    
    NSInteger CountForRed = 0;
    NSInteger CountForBlue = 0;

    switch ([currentID integerValue]) {
        case 3:{
            CountForRed = [[SelectionNumManager shared] calculationsTheCombinationWith:redCount andExtractionCount:6];
            CountForBlue = blueCount;
        }
            break;
        case 4:{
            CountForRed = [[SelectionNumManager shared] calculationsTheCombinationWith:redCount andExtractionCount:5];
            CountForBlue = [[SelectionNumManager shared] calculationsTheCombinationWith:blueCount andExtractionCount:2];;
        }
            break;
        default:
            break;
    }
    
    NSInteger totalCount = CountForRed*CountForBlue;
    
    
    NSMutableAttributedString *countAttString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%ld注",totalCount]];
    [countAttString addAttribute:NSForegroundColorAttributeName
                          value:[UIColor redColor]
                          range:NSMakeRange(0, [countAttString length]-1)];
    NSMutableAttributedString *moneyAttString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@" %ld元",totalCount*2]];
    [moneyAttString addAttribute:NSForegroundColorAttributeName
                           value:[UIColor redColor]
                           range:NSMakeRange(0, [moneyAttString length]-1)];
    
    [countAttString appendAttributedString:moneyAttString];
    self.CalculateMoneyLabel.attributedText = countAttString;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSString* titleString = [NSString stringWithFormat:@"%@普通选号",[SelectionNumManager shared].currentLotteryName];
    
    titleButton =[UIButton buttonWithType:UIButtonTypeCustom];
    titleButton.frame=CGRectMake(20, 20, 100, 40);
    [titleButton setTitle:titleString forState:UIControlStateNormal];
    [titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIImage* buttonImage =[UIImage imageNamed:@"YL_白色向下"];
    [titleButton setImage:buttonImage forState:UIControlStateNormal];
    [titleButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -buttonImage.size.width, 0, buttonImage.size.width)];
    [titleButton setImageEdgeInsets:UIEdgeInsetsMake(0, titleButton.frame.size.width+buttonImage.size.width*2, 0, 0)];
    
    [titleButton addTarget:self action:@selector(showStyleView) forControlEvents:UIControlEventTouchUpInside];
//    titleButton.layer.borderColor = [UIColor yellowColor].CGColor;
//    titleButton.layer.borderWidth = 2;
//    titleButton.layer.masksToBounds = NO;
    self.navigationItem.titleView =titleButton;
    
    styleIndex = 0;
    
    self.seletedRedNumArray = [NSMutableArray arrayWithCapacity:0];
    self.seletedTugRedNumArray = [NSMutableArray arrayWithCapacity:0];
    self.seletedBlueNumArray = [NSMutableArray arrayWithCapacity:0];
    self.seletedTugBlueNumArray = [NSMutableArray arrayWithCapacity:0];
    
    randomRednumberViewArray = [NSMutableArray arrayWithCapacity:0];
    randomBluenumberViewArray = [NSMutableArray arrayWithCapacity:0];
    tugRedNumberViewArray = [NSMutableArray arrayWithCapacity:0];
    tugBlueNumberViewArray = [NSMutableArray arrayWithCapacity:0];
    
    currentID = [SelectionNumManager shared].currentLotteryID;
    [self loadBallArrayWith:currentID];


    [[SelectionNumManager shared] getDataWithLotteryID:currentID andActionID:@"201" andCallBack:^(BOOL load, NSDictionary *resObj) {
        if (load) {
            self.nameDic = resObj[@"data"];
            [self showNameAndEndTime];
        }
    }];
}

-(void)showStyleView{
    openStyleView = !openStyleView;
    [self updateViewConstraints];
}

-(void)showNameAndEndTime{
    self.nameAndEndTime.text = [NSString stringWithFormat:@"%@ %@",self.nameDic[@"Name"],self.nameDic[@"BuyEndTime"]];
}


#pragma mark - 设置红蓝球区
-(void)loadBallArrayWith:(NSString*)lotteryID{

    NSInteger countBallInRow = (self.view.frame.size.width-spacingWith)/(ballWidth+spacingWith);
    
    self.randomButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.randomButton setTitle:@"" forState:UIControlStateNormal];
    [self.randomButton setImage:[UIImage imageNamed:@"YL_yyy"] forState:UIControlStateNormal];
    self.randomButton.frame = CGRectMake(self.view.frame.size.width-95, 5, 90, 30);
    [self.randomButton addTarget:self action:@selector(randomAction:) forControlEvents:UIControlEventTouchUpInside];
    
    __weak typeof(self)weakSelf = self;
    //普通红球
    self.redBallArray = [[SelectionNumManager shared] redNumberArrayWith:lotteryID];
    self.redBallBoxView = [[UIView alloc] initWithFrame:CGRectMake(0, ballWidth, self.view.frame.size.width, (([self.redBallArray count]/countBallInRow)+1)*(ballWidth+spacingWith))];
    for (int i = 0; i<[self.redBallArray count]; i++) {
        SelectedNumberView* view = [[UINib nibWithNibName:@"NumberView" bundle:[NSBundle mainBundle]] instantiateWithOwner:nil options:nil][0];
        view.frame = CGRectMake((i%countBallInRow)*(ballWidth+spacingWith)+spacingWith, (i/countBallInRow)*(ballWidth+spacingWith)+5, ballWidth, ballWidth);
        view.numberMainColor = [UIColor redColor];
        view.numberLabel.text = self.redBallArray[i];
        __weak typeof(view)weakView = view;
        view.TapCallback = ^(BOOL selected, NSString *numberText) {
            if (selected) {
                [weakSelf.seletedRedNumArray addObject:numberText];
                for (SelectedNumberView* checkView in self->tugRedNumberViewArray) {
                    if ([checkView.numberLabel.text isEqualToString:numberText]) {
                        [checkView setNormalState];
                    }
                }
            }else{
                [weakSelf.seletedRedNumArray removeObject:numberText];
            }
            if ([[self checkNumberCountWith:1] hasPrefix:@"最多"]) {
                [EasyTextView showErrorText:[self checkNumberCountWith:1]];
                [weakView setNormalState];
            }
            [self CalculateMoneyAction];
        };
        [randomRednumberViewArray addObject:view];
        [self.redBallBoxView addSubview:view];
    }
    //普通蓝球
    self.blueBallArray = [[SelectionNumManager shared] blueNumberArrayWith:lotteryID];
    self.blueBallBoxView = [[UIView alloc] initWithFrame:CGRectMake(0, ballWidth, self.view.frame.size.width, (([self.blueBallArray count]/countBallInRow)+1)*(ballWidth+spacingWith))];
    for (int i = 0; i<[self.blueBallArray count]; i++) {
        SelectedNumberView* view = [[UINib nibWithNibName:@"NumberView" bundle:[NSBundle mainBundle]] instantiateWithOwner:nil options:nil][0];
        view.frame = CGRectMake((i%countBallInRow)*(ballWidth+spacingWith)+spacingWith, (i/countBallInRow)*(ballWidth+spacingWith)+5, ballWidth, ballWidth);
        view.numberMainColor = [UIColor blueColor];
        view.numberLabel.text = self.blueBallArray[i];
        __weak typeof(view)weakView = view;
        view.TapCallback = ^(BOOL selected, NSString *numberText) {
            if (selected) {
                [weakSelf.seletedBlueNumArray addObject:numberText];
                for (SelectedNumberView* checkView in self->tugBlueNumberViewArray) {
                    if ([checkView.numberLabel.text isEqualToString:numberText]) {
                        [checkView setNormalState];
                    }
                }
            }else{
                [weakSelf.seletedBlueNumArray removeObject:numberText];
            }
            if ([[self checkNumberCountWith:2] hasPrefix:@"最多"]) {
                [EasyTextView showErrorText:[self checkNumberCountWith:2]];
                [weakView setNormalState];
            }
            [self CalculateMoneyAction];
        };
        [randomBluenumberViewArray addObject:view];
        [self.blueBallBoxView addSubview:view];
    }
    
    //胆拖
    self.TugRedBallArray = [[SelectionNumManager shared] redNumberArrayWith:lotteryID];
    self.TugRedBallBoxView = [[UIView alloc] initWithFrame:CGRectMake(0, ballWidth, self.view.frame.size.width, (([self.TugRedBallArray count]/countBallInRow)+1)*(ballWidth+spacingWith))];
    for (int i = 0; i<[self.TugRedBallArray count]; i++) {
        SelectedNumberView* view = [[UINib nibWithNibName:@"NumberView" bundle:[NSBundle mainBundle]] instantiateWithOwner:nil options:nil][0];
        view.frame = CGRectMake((i%countBallInRow)*(ballWidth+spacingWith)+spacingWith, (i/countBallInRow)*(ballWidth+spacingWith)+5, ballWidth, ballWidth);
        view.numberMainColor = [UIColor redColor];
        view.numberLabel.text = self.TugRedBallArray[i];
        view.TapCallback = ^(BOOL selected, NSString *numberText) {
            if (selected) {
                [weakSelf.seletedTugRedNumArray addObject:numberText];
                for (SelectedNumberView* checkView in self->randomRednumberViewArray) {
                    if ([checkView.numberLabel.text isEqualToString:numberText]) {
                        [checkView setNormalState];
                    }
                }
            }else{
                [weakSelf.seletedTugRedNumArray removeObject:numberText];
            }
            [self CalculateMoneyAction];
        };
        [tugRedNumberViewArray addObject:view];
        [self.TugRedBallBoxView addSubview:view];
    }

    //胆拖蓝球
    self.TugblueBallArray = [[SelectionNumManager shared] blueNumberArrayWith:lotteryID];
    self.TugblueBallBoxView = [[UIView alloc] initWithFrame:CGRectMake(0, ballWidth, self.view.frame.size.width, (([self.TugblueBallArray count]/countBallInRow)+1)*(ballWidth+spacingWith))];
    for (int i = 0; i<[self.TugblueBallArray count]; i++) {
        SelectedNumberView* view = [[UINib nibWithNibName:@"NumberView" bundle:[NSBundle mainBundle]] instantiateWithOwner:nil options:nil][0];
        view.frame = CGRectMake((i%countBallInRow)*(ballWidth+spacingWith)+spacingWith, (i/countBallInRow)*(ballWidth+spacingWith)+5, ballWidth, ballWidth);
        view.numberMainColor = [UIColor blueColor];
        view.numberLabel.text = self.TugRedBallArray[i];
        view.TapCallback = ^(BOOL selected, NSString *numberText) {
            if (selected) {
                [weakSelf.seletedTugBlueNumArray addObject:numberText];
                for (SelectedNumberView* checkView in self->randomBluenumberViewArray) {
                    if ([checkView.numberLabel.text isEqualToString:numberText]) {
                        [checkView setNormalState];
                    }
                }
            }else{
                [weakSelf.seletedTugBlueNumArray removeObject:numberText];
            }
            [self CalculateMoneyAction];
        };
        [tugBlueNumberViewArray addObject:view];
        [self.TugblueBallBoxView addSubview:view];
    }
    
    
    [self.numberTableView reloadData];
}

#pragma mark - 近期开奖
- (IBAction)recentWinNumberAction:(id)sender {
//
    UIViewController* viewController = [[UIStoryboard storyboardWithName:@"SelectedNumber" bundle:nil] instantiateViewControllerWithIdentifier:@"RecentWinNumberViewController"];
    
    [viewController setPopinTransitionStyle:BKTPopinTransitionStyleCrossDissolve];
    [viewController setPopinTransitionDirection:BKTPopinTransitionDirectionTop];
    
    CGRect presentationRect = CGRectInset(self.view.bounds, 0, 100);
    [self.navigationController presentPopinController:viewController fromRect:presentationRect animated:YES completion:^{
        NSLog(@"Popin presented !");
    }];
}

#pragma mark - 确定
- (IBAction)doneAction:(id)sender {
    if ([OpenLoginManager openLoginPageWithController:self]) {
        return;
    }
    if ([[self checkNumberCountWith:0] length]>0) {
        [EasyTextView showErrorText:[self checkNumberCountWith:0]];
        return;
    }
    NSMutableArray* redArray = [NSMutableArray arrayWithCapacity:0];
    [redArray addObjectsFromArray:self.seletedRedNumArray];
    [redArray addObjectsFromArray:self.seletedTugRedNumArray];
    
    NSMutableArray* blueArray = [NSMutableArray arrayWithCapacity:0];
    [blueArray addObjectsFromArray:self.seletedBlueNumArray];
    [blueArray addObjectsFromArray:self.seletedTugBlueNumArray];
    
    NSUInteger redNumberCheckCount = 0;
    NSUInteger blueNumberCheckCount = 0;
    switch ([currentID integerValue]) {
        case 3:
            redNumberCheckCount = 6;
            blueNumberCheckCount = 1;
            break;
        case 4:
            redNumberCheckCount = 5;
            blueNumberCheckCount = 2;
            break;
        default:
            break;
    }
    
    if ([redArray count]<redNumberCheckCount) {
        [EasyTextView showErrorText:[NSString stringWithFormat:@"请至少选择%ld个红球",redNumberCheckCount]];
        return;
    }
    
    if ([blueArray count]<blueNumberCheckCount) {
        [EasyTextView showErrorText:[NSString stringWithFormat:@"请至少选择%ld个蓝球",blueNumberCheckCount]];
        return;
    }
    
    [redArray sortedArrayUsingSelector:@selector(compare:)];
    
    
    NSString* redString = [redArray componentsJoinedByString:@","];
    NSString* blueString = [blueArray componentsJoinedByString:@","];
    
    NSLog(@"%@+%@",redString,blueString);
    
    CollectionNumberModel *model1 = [CollectionNumberModel setModelWithType:[SelectionNumManager shared].currentLotteryID number:[NSString stringWithFormat:@"%@+%@",redString,blueString]];

    [CollectionNumberManager collectionNumberWithArray:@[model1]];
    
    
    
}
#pragma mark - 删除
- (IBAction)deleteAction:(id)sender {
    [self removeAllHighLightState];
}

-(void)removeAllHighLightState{
    [self.seletedRedNumArray removeAllObjects];
    [self.seletedBlueNumArray removeAllObjects];
    [self.seletedTugRedNumArray removeAllObjects];
    [self.seletedTugBlueNumArray removeAllObjects];
    for (SelectedNumberView* view in randomRednumberViewArray) {
        [view setNormalState];
    }
    for (SelectedNumberView* view in randomBluenumberViewArray) {
        [view setNormalState];
    }
    for (SelectedNumberView* view in tugRedNumberViewArray) {
        [view setNormalState];
    }
    for (SelectedNumberView* view in tugBlueNumberViewArray) {
        [view setNormalState];
    }
}


-(void)randomAction:(id)sender {
    [self removeAllHighLightState];
    [self.seletedRedNumArray removeAllObjects];
    [self.seletedBlueNumArray removeAllObjects];
    NSArray* redArray = [[SelectionNumManager shared] randomRedNumberActionWithLottoryID:currentID];
    for (SelectedNumberView* view in randomRednumberViewArray) {
        for (NSString* numberString in redArray) {
            if ([view.numberLabel.text isEqualToString:numberString]) {
                [view setHighLightState];
            }
        }
    }
    
    NSArray* blueArray = [[SelectionNumManager shared] randomBlueNumberActionWithLottoryID:currentID];
    
    for (SelectedNumberView* view in randomBluenumberViewArray) {
        for (NSString* numberString in blueArray) {
            if ([view.numberLabel.text isEqualToString:numberString]) {
                [view setHighLightState];
            }
        }
    }
    
}




#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger numberOfRows = 0;
    switch (styleIndex) {
        case 0:
            numberOfRows = 2;
            break;
        case 1:
            numberOfRows = ([currentID integerValue]==3)?3:4;
            break;
        default:
            break;
    }
    return numberOfRows;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"numberTableCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"numberTableCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UIView* lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, 3)];
    lineView.backgroundColor = [UIColor lightGrayColor];
    
    UILabel* desLabel = [cell.contentView viewWithTag:1001];
    if (!desLabel) {
        desLabel = [[UILabel alloc] initWithFrame:CGRectMake(spacingWith, 0, 300, ballWidth)];
        desLabel.tag = 1001;
        desLabel.font = [UIFont systemFontOfSize:12];
        [cell.contentView addSubview:desLabel];
    }
    
    NSString* redDesString = @"";
    NSString* tugRedDesString = @"";
    NSString* blueDesString = @"";
    switch (styleIndex) {
        case 0:{
            redDesString = ([currentID integerValue]==3)?@"至少选择6个红球":@"至少选择5个红球";
            tugRedDesString = ([currentID integerValue]==3)?@"":@"";
            blueDesString = ([currentID integerValue]==3)?@"至少选择1个蓝球":@"至少选择2个蓝球";
            switch (indexPath.row) {
                case 0:{
                    desLabel.text = redDesString;
                    [self.redBallBoxView removeFromSuperview];
                    self.randomButton.hidden = NO;
                    [cell.contentView addSubview:self.randomButton];
                    [cell.contentView addSubview:self.redBallBoxView];
                }
                    break;
                case 1:
                    desLabel.text = blueDesString;
                    [self.TugRedBallBoxView removeFromSuperview];
                    [cell.contentView addSubview:lineView];
                    [cell.contentView addSubview:self.blueBallBoxView];
                    break;
                default:
                    break;
            }
        }
            break;
        case 1:{
            redDesString = ([currentID integerValue]==3)?@"胆码区-红球，认为必出的号码，选择1-5个":@"胆码区-红球，认为必出的号码，选择1-4个";
            tugRedDesString = ([currentID integerValue]==3)?@"拖码区-红球，认为可能的号码，至少2个":@"拖码区-红球，认为可能的号码，至少2个";
            blueDesString = ([currentID integerValue]==3)?@"至少选择1个蓝球":@"胆码区-蓝球，认为必出的号码，至多选择1个";
            switch (indexPath.row) {
                case 0:{
                    desLabel.text = redDesString;
                    [self.redBallBoxView removeFromSuperview];
                    self.randomButton.hidden = YES;
                    [cell.contentView addSubview:self.redBallBoxView];
                }
                    break;
                case 1:
                    desLabel.text = tugRedDesString;
                    [self.TugRedBallBoxView removeFromSuperview];
                    [cell.contentView addSubview:lineView];
                    [cell.contentView addSubview:self.TugRedBallBoxView];
                    break;
                case 2:
                    desLabel.text = blueDesString;
                    [self.blueBallBoxView removeFromSuperview];
                    [cell.contentView addSubview:lineView];
                    [cell.contentView addSubview:self.blueBallBoxView];
                    break;
                case 3:
                    desLabel.text = @"拖码区-蓝球，认为可能的号码，至少2个";
                    [self.TugblueBallBoxView removeFromSuperview];
                    [cell.contentView addSubview:lineView];
                    [cell.contentView addSubview:self.TugblueBallBoxView];
                    break;
                default:
                    break;
            }
        }
            break;
        default:
            break;
    }
    

    
    
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat backHeight = 0;
    switch (styleIndex) {
        case 0:{
            switch (indexPath.row) {
                case 0:
                    backHeight = self.redBallBoxView.frame.size.height+ballWidth*1.5;
                    break;
                case 1:
                    backHeight = self.blueBallBoxView.frame.size.height+ballWidth*1.5;
                default:
                    break;
            }
        }
            break;
        case 1:{
            switch (indexPath.row) {
                case 0:
                    backHeight = self.redBallBoxView.frame.size.height+ballWidth*1.5;
                    break;
                case 1:
                    backHeight = self.TugRedBallBoxView.frame.size.height+ballWidth*1.5;
                    break;
                case 2:
                    backHeight = self.blueBallBoxView.frame.size.height+ballWidth*1.5;
                    break;
                case 3:
                    backHeight = self.TugblueBallBoxView.frame.size.height+ballWidth*1.5;
                default:
                    break;
            }
        }
            break;
            
        default:
            break;
    }

    return backHeight;
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
